package com.clstu.socket;

import com.sun.media.jfxmediaimpl.HostUtils;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTCP03Server {
    public static void main(String[] args) throws IOException {//运用字节流
        ServerSocket serverSocket = new ServerSocket(9999);
        Socket socket = serverSocket.accept();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(bufferedReader.readLine());
        bufferedWriter.write("hello , client ！！！（字符流）");
        bufferedWriter.newLine();//插入换行代表结束 对方也用readLine() 接受
        bufferedWriter.flush();//手动flush刷新 数据才会进入数据通道
        //socket.shutdownOutput();
        serverSocket.close();
        bufferedReader.close();
        bufferedWriter.close();
        socket.close();
    }
}
